<%@ page import="com.ws.haungjia.utils.Res" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>修改路线信息</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap-datepicker.min.css">
    <style>
        .route-img-preview {
            max-height: 200px;
            max-width: 100%;
            margin-top: 10px;
        }
        .upload-area {
            border: 2px dashed #ccc;
            padding: 20px;
            text-align: center;
            margin-bottom: 20px;
            cursor: pointer;
        }
        .upload-area:hover {
            border-color: #aaa;
        }
        .form-section {
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 1px solid #eee;
        }
        .form-section-title {
            margin-bottom: 20px;
            color: #2c3e50;
            font-weight: bold;
        }
    </style>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-12">
            <h2>修改路线信息</h2>
            <div class="card">
                <div class="card-body">
                    <form action="${pageContext.request.contextPath}/luxing/xiugai" method="post" enctype="multipart/form-data">
                        <input type="hidden" name="packageID" value="${route.packageID}">

                        <!-- 基本信息部分 -->
                        <div class="form-section">
                            <h4 class="form-section-title">基本信息</h4>
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="name">路线名称</label>
                                        <input type="text" class="form-control" id="name" name="name" value="${route.name}" required>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="fenlie">分类</label>
                                        <select class="form-control" id="fenlie" name="Fid" required>
                                            <c:forEach items="${fenlieList}" var="fenlie">
                                                <option value="${fenlie.fid}" ${route.fenlie.fid == fenlie.fid ? 'selected' : ''}>${fenlie.fname}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="jiage">价格(元)</label>
                                        <input type="number" class="form-control" id="jiage" name="jiage" value="${route.jiage}" required min="0">
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="tianshu">天数</label>
                                        <input type="number" class="form-control" id="tianshu" name="tianshu" value="${route.tianshu}" required min="1">
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="renshu">最大人数</label>
                                        <input type="number" class="form-control" id="renshu" name="renshu" value="${route.renshu}" required min="1">
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="shangjia">商家</label>
                                        <select class="form-control" id="shangjia" name="sid" required>
                                            <c:forEach items="${shangjiaList}" var="shangjia">
                                                <option value="${shangjia.sid}" ${route.shangjia.sid == shangjia.sid ? 'selected' : ''}>${shangjia.sname}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="zhuangtai">状态</label>
                                        <select class="form-control" id="zhuangtai" name="zhuangtai" required>
                                            <option value="1" ${route.zhuangtai == 1 ? 'selected' : ''}>活跃</option>
                                            <option value="2" ${route.zhuangtai == 2 ? 'selected' : ''}>下架</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- 图片上传部分 -->
                        <div class="form-section">
                            <h4 class="form-section-title">路线图片</h4>
                            <div class="form-group">
                                <label>当前主图</label><br>
                                <img src="<%=Res.fileUri%>${route.zhutu}" class="route-img-preview" id="currentImage">
                            </div>
                            <div class="form-group">
                                <label for="zhutu">更换主图</label>
                                <div class="upload-area" onclick="document.getElementById('zhutu').click()">
                                    <i class="fa fa-cloud-upload fa-3x"></i>
                                    <p>点击上传新图片</p>
                                    <input type="file" id="zhutu" name="tupian" style="display: none;" accept="image/*" onchange="previewImage(this)">
                                </div>
                                <img id="imagePreview" class="route-img-preview" style="display: none;">
                            </div>
                        </div>

<%--                        <!-- 路线详情部分 -->--%>
<%--                        <div class="form-section">--%>
<%--                            <h4 class="form-section-title">路线详情</h4>--%>
<%--                            <div class="form-group">--%>
<%--                                <label for="jianjie">路线简介</label>--%>
<%--                                <textarea class="form-control" id="jianjie" name="jianjie" rows="3">${route.jianjie}</textarea>--%>
<%--                            </div>--%>
<%--                            <div class="form-group">--%>
<%--                                <label for="xingcheng">行程安排</label>--%>
<%--                                <textarea class="form-control" id="xingcheng" name="xingcheng" rows="5">${route.xingcheng}</textarea>--%>
<%--                            </div>--%>
<%--                            <div class="form-group">--%>
<%--                                <label for="zhuyi">注意事项</label>--%>
<%--                                <textarea class="form-control" id="zhuyi" name="zhuyi" rows="3">${route.zhuyi}</textarea>--%>
<%--                            </div>--%>
<%--                        </div>--%>

                        <div class="form-group text-center">
                            <button type="submit" class="btn btn-primary btn-lg mr-3">
                                <i class="fa fa-save"></i> 保存修改
                            </button>
                            <a href="${pageContext.request.contextPath}/route/list" class="btn btn-secondary btn-lg">
                                <i class="fa fa-times"></i> 取消返回
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script>
    // 图片预览功能
    function previewImage(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function(e) {
                $('#imagePreview').attr('src', e.target.result).show();
                $('#currentImage').hide();
            }
            reader.readAsDataURL(input.files[0]);
        }
    }

    // 表单验证
    $(document).ready(function() {
        $('form').submit(function() {
            // 可以在这里添加额外的表单验证逻辑
            return true;
        });
    });
</script>
</body>
</html>